<?php


namespace coco;


use coco\client\Redis as ClientRedis;

class SingletonHandle
{

    protected static $handle = [];

    public static function redis(array $option = []): ClientRedis
    {
        if (empty(self::$handle['redis'])) {
            $reids_config = Config::getInstance()->get('redis');
            $host = $option['host'] ?? $reids_config['host'] ?? '127.0.0.1';
            $option = [
                'port' => $option['port'] ?? $reids_config['port'] ?? 6379,
                'password' => $option['password'] ?? $reids_config['password'] ?? '',
                'db' => $option['db'] ?? $reids_config['db'] ?? '',
                'reconnect' => $option['reconnect'] ?? $reids_config['reconnect'] ?? 10,
            ];
            self::$handle['redis'] = new ClientRedis($host, $option);
        }
        return self::$handle['redis'];
    }

}